﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GroundWater
{
    public class SimplePageBase : Page
    {
        //设置页面主题
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            //设置页面主题
            this.Theme = ApplicationContext.Theme;
        }

        protected override void OnLoad(EventArgs e)
        {
            // 加载样式

            // 加载JavaScript

            base.OnLoad(e);
        }

        // 应该为静态方法，或singleton class的方法
        protected virtual void InsertCache(string key, Object obj)
        {
            Cache.Insert(key, obj, null, DateTime.Now.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);
            //Cache.Add(key, obj, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

        }

        // 应该为静态方法，或singleton class的方法
        protected virtual void InsertCacheInstant(string key, Object obj)
        {
            Cache.Insert(key, obj, null, DateTime.Now.AddSeconds(10), System.Web.Caching.Cache.NoSlidingExpiration);
            //Cache.Add(key, obj, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
        }
        //弹出消息背景不是空白
        protected void RegisterClientScript(string js, Literal lbl)
        {
            //if (!ClientScript.IsStartupScriptRegistered("_message_"))
            //    ClientScript.RegisterStartupScript(this.GetType(), "_message_", "<script language='javascript'> alert('" + message + "'); </script>");

            lbl.Text = "<script type=\"text/javascript\">" + js + "</script>";
        }

        protected override void OnError(EventArgs e)
        {
            base.OnError(e);

            //Exception objErr = Server.GetLastError().GetBaseException();
            //string err = "<b>Error Caught in Page_Error event</b><hr><br>" +
            //        "<br><b>Error in:</b>" + Request.Url.ToString() +
            //        "<br><b>Error Message:</b>" + objErr.Message.ToString() +
            //        "<br><b>Stack Trace:</b><br>" +
            //                  objErr.StackTrace.Replace(" 在 ", "<br /> 在 ");
            ////Response.Write(err.ToString());

            //InsertCacheInstant(ApplicationContext.ActualUserId.ToString(), err);

            //Server.ClearError();
        }
    }
}
